package steampunk;

import java.awt.event.KeyEvent;

import steampunk.entities.Entity;

public class PlayerControls {

	private Entity player;
	
	public PlayerControls(Entity player) {
		this.player = player;
	}
	public PlayerControls() {
		this(GameVars.getInstance().getPlayer());
	}

	public void setPlayer(Entity player) {
		this.player = player;
	}
	
	public void mouseClicked(int x, int y) {
		
	}
	public void mousePressed(int x, int y) {
		
	}
	public void mouseReleased(int x, int y) {
		
	}
	
	public void mouseMoved(int x, int y) {
		
	}
	public void mouseDragged(int x, int y) {
		
	}
	
	
	public void keyPressed(int code, int x, int y) {
		if (player == null) return;
		switch (code) {
		case KeyEvent.VK_A:
		case KeyEvent.VK_LEFT:
			player.triggerAction("left");
			break;
		case KeyEvent.VK_D:
		case KeyEvent.VK_RIGHT:
			player.triggerAction("right");
			break;
		case KeyEvent.VK_W:
		case KeyEvent.VK_UP:
			player.triggerAction("jump");
			break;
		case KeyEvent.VK_S:
		case KeyEvent.VK_DOWN:
			player.triggerAction("down");
			break;
		case KeyEvent.VK_O:
			player.triggerAction("reset");
			break;
		case KeyEvent.VK_NUMPAD8:
			player.triggerAction("fly up");
			break;
		case KeyEvent.VK_NUMPAD2:
			player.triggerAction("fly down");
			break;
		case KeyEvent.VK_NUMPAD4:
			player.triggerAction("fly left");
			break;
		case KeyEvent.VK_NUMPAD6:
			player.triggerAction("fly right");
			break;
		}
	}
	
	public void keyReleased(int code, int x, int y) {
		if (player == null) return;
		switch (code) {
		case KeyEvent.VK_A:
		case KeyEvent.VK_LEFT:
			player.untriggerAction("left");
			break;
		case KeyEvent.VK_D:
		case KeyEvent.VK_RIGHT:
			player.untriggerAction("right");
			break;
		case KeyEvent.VK_W:
		case KeyEvent.VK_UP:
			player.untriggerAction("jump");
			break;
		case KeyEvent.VK_NUMPAD8:
			player.untriggerAction("fly up");
			break;
		case KeyEvent.VK_NUMPAD2:
			player.untriggerAction("fly down");
			break;
		case KeyEvent.VK_NUMPAD4:
			player.untriggerAction("fly left");
			break;
		case KeyEvent.VK_NUMPAD6:
			player.untriggerAction("fly right");
			break;
		}
	}
	
	public void keyTyped(int code, int x, int y) {
		
	}
}
